package SoftwareConstruction;

import java.util.Date;

public class DefensiveCopying {
    public static void main(String[] args) {
        Date start = new Date();
        Date end = new Date();
        Period p = new Period(start, end);
        p.end().setYear(78);
    }
}
final class Period{
    private final Date start,end;

    public Period(Date start,Date end) {
        if(start.after(end))
            throw new IllegalArgumentException(start+">"+end);
        this.start = start;
        this.end = end;
    }
    public Date start(){
        return new Date(start.getTime());
    }
    public Date end(){
        return new Date(end.getTime());
    }
}
